import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../models/order.dart';
import '../widgets/empty_state.dart';
import '../pages/order_detail_page.dart';
import '../widgets/grab_order_dialog.dart';

class GrabOrdersPage extends StatefulWidget {
  const GrabOrdersPage({super.key});

  @override
  State<GrabOrdersPage> createState() => _GrabOrdersPageState();
}

class _GrabOrdersPageState extends State<GrabOrdersPage> {
  final RefreshController _refreshController = RefreshController();
  
  // 筛选条件
  String? _selectedServiceType;
  RangeValues _priceRange = const RangeValues(0, 1000);
  bool _hasElevator = false;
  bool _needPackaging = false;
  bool _needDisassembly = false;

  // 服务类型选项
  final List<String> _serviceTypes = [
    '居民搬家',
    '办公室搬迁',
    '小型搬运',
    '长途搬家',
  ];

  // 模拟订单数据
  final List<Order> _orders = [
    Order(
      id: '001',
      fromAddress: '北京市朝阳区建国路88号',
      address: '北京市海淀区中关村大街1号',
      status: '待抢单',
      time: '2024-03-21 14:30',
      price: 288.00,
      customerName: '张先生',
      customerPhone: '138****8888',
      serviceType: '居民搬家',
      requirements: ['有电梯', '需要拆装家具', '需要包装服务'],
      distance: 3.5,
    ),
    Order(
      id: '002',
      fromAddress: '北京市西城区复兴门外大街1号',
      address: '北京市东城区东长安街1号',
      status: '待抢单',
      time: '2024-03-21 15:00',
      price: 366.00,
      customerName: '李女士',
      customerPhone: '139****9999',
      serviceType: '办公室搬迁',
      requirements: ['需要搬运大型设备', '周末搬迁', '需要包装服务'],
      distance: 5.0,
    ),
    Order(
      id: '003',
      fromAddress: '北京市海淀区学院路15号',
      address: '北京市昌平区回龙观东大街1号',
      status: '待抢单',
      time: '2024-03-21 16:30',
      price: 188.00,
      customerName: '王先生',
      customerPhone: '137****7777',
      serviceType: '居民搬家',
      requirements: ['无电梯', '三楼'],
      distance: 2.0,
    ),
    // 添加更多订单数据...
  ];

  @override
  void dispose() {
    _refreshController.dispose();
    super.dispose();
  }

  // 处理下拉刷新
  Future<void> _onRefresh() async {
    try {
      await Future.delayed(const Duration(seconds: 2));
      if (mounted) {
        setState(() {
          // 模拟刷新数据
          _orders.insert(0, Order(
            id: DateTime.now().toString(),
            fromAddress: '北京市朝阳区三里屯1号',
            address: '北京市朝阳区望京西路1号',
            status: '待抢单',
            time: '2024-03-21 18:00',
            price: 299.00,
            customerName: '赵女士',
            customerPhone: '135****5555',
            serviceType: '居民搬家',
            requirements: ['有电梯', '需要包装服务'],
            distance: 4.0,
          ));
        });
      }
      _refreshController.refreshCompleted();
    } catch (e) {
      _refreshController.refreshFailed();
    }
  }

  // 处理上拉加载
  Future<void> _onLoading() async {
    await Future.delayed(const Duration(seconds: 1));
    setState(() {
      if (_orders.length < 20) {
        // 模拟加载更多数据
        _orders.add(Order(
          id: DateTime.now().toString(),
          fromAddress: '北京市海淀区中关村南大街1号',
          address: '北京市海淀区上地十街1号',
          status: '待抢单',
          time: '2024-03-22 09:00',
          price: 255.00,
          customerName: '钱先生',
          customerPhone: '136****6666',
          serviceType: '居民搬家',
          requirements: ['有电梯', '需要拆装家具'],
          distance: 6.0,
        ));
        _refreshController.loadComplete();
      } else {
        _refreshController.loadNoData();
      }
    });
  }

  /// 获取筛选后的订单列表
  List<Order> get _filteredOrders {
    return _orders.where((order) {
      // 服务类型筛选
      if (_selectedServiceType != null && order.serviceType != _selectedServiceType) {
        return false;
      }
      
      // 价格区间筛选
      if (order.price < _priceRange.start || order.price > _priceRange.end) {
        return false;
      }
      
      // 其他条件筛选
      if (_hasElevator && !order.requirements.contains('有电梯')) {
        return false;
      }
      if (_needPackaging && !order.requirements.contains('需要包装服务')) {
        return false;
      }
      if (_needDisassembly && !order.requirements.contains('需要拆装家具')) {
        return false;
      }
      
      return true;
    }).toList();
  }

  /// 显示筛选面板
  void _showFilterSheet() {
    // 保存当前筛选条件，用于取消时恢复
    final currentServiceType = _selectedServiceType;
    final currentPriceRange = _priceRange;
    final currentHasElevator = _hasElevator;
    final currentNeedPackaging = _needPackaging;
    final currentNeedDisassembly = _needDisassembly;

    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => StatefulBuilder(
        builder: (context, setState) {
          return Container(
            height: MediaQuery.of(context).size.height * 0.75,
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(
                top: Radius.circular(16),
              ),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Container(
                  padding: const EdgeInsets.all(16),
                  decoration: const BoxDecoration(
                    border: Border(
                      bottom: BorderSide(
                        color: Color(0xFFEEEEEE),
                      ),
                    ),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      TextButton(
                        onPressed: () {
                          this.setState(() {
                            _selectedServiceType = currentServiceType;
                            _priceRange = currentPriceRange;
                            _hasElevator = currentHasElevator;
                            _needPackaging = currentNeedPackaging;
                            _needDisassembly = currentNeedDisassembly;
                          });
                          Navigator.pop(context);
                        },
                        child: Text(
                          '取消',
                          style: TextStyle(
                            color: Colors.grey[600],
                            fontSize: 15,
                          ),
                        ),
                      ),
                      const Text(
                        '筛选',
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                      TextButton(
                        onPressed: () async {
                          Navigator.pop(context);
                          this.setState(() {});
                          _refreshController.requestRefresh();
                          await Future.delayed(const Duration(milliseconds: 500));
                          _refreshController.refreshCompleted();
                        },
                        child: const Text(
                          '确定',
                          style: TextStyle(
                            color: Color(0xFFFF5722),
                            fontSize: 15,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: SingleChildScrollView(
                    padding: const EdgeInsets.all(16),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        // 服务类型
                        const Text(
                          '服务类型',
                          style: TextStyle(
                            fontSize: 15,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        const SizedBox(height: 12),
                        Wrap(
                          spacing: 8,
                          runSpacing: 8,
                          children: _serviceTypes.map((type) {
                            final isSelected = type == _selectedServiceType;
                            return InkWell(
                              onTap: () {
                                setState(() {
                                  _selectedServiceType = isSelected ? null : type;
                                });
                              },
                              child: Container(
                                padding: const EdgeInsets.symmetric(
                                  horizontal: 16,
                                  vertical: 8,
                                ),
                                decoration: BoxDecoration(
                                  color: isSelected
                                      ? const Color(0xFFFF5722).withOpacity(0.1)
                                      : Colors.grey[100],
                                  borderRadius: BorderRadius.circular(20),
                                  border: Border.all(
                                    color: isSelected
                                        ? const Color(0xFFFF5722)
                                        : Colors.transparent,
                                  ),
                                ),
                                child: Text(
                                  type,
                                  style: TextStyle(
                                    fontSize: 13,
                                    color: isSelected
                                        ? const Color(0xFFFF5722)
                                        : Colors.grey[700],
                                  ),
                                ),
                              ),
                            );
                          }).toList(),
                        ),
                        const SizedBox(height: 24),
                        // 价格区间
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            const Text(
                              '价格区间',
                              style: TextStyle(
                                fontSize: 15,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                            Text(
                              '¥${_priceRange.start.toInt()} - ¥${_priceRange.end.toInt()}',
                              style: TextStyle(
                                fontSize: 13,
                                color: Colors.grey[600],
                              ),
                            ),
                          ],
                        ),
                        const SizedBox(height: 8),
                        RangeSlider(
                          values: _priceRange,
                          min: 0,
                          max: 1000,
                          divisions: 20,
                          activeColor: const Color(0xFFFF5722),
                          inactiveColor: Colors.grey[200],
                          labels: RangeLabels(
                            '¥${_priceRange.start.toInt()}',
                            '¥${_priceRange.end.toInt()}',
                          ),
                          onChanged: (values) {
                            setState(() {
                              _priceRange = values;
                            });
                          },
                        ),
                        const SizedBox(height: 24),
                        // 其他条件
                        const Text(
                          '其他条件',
                          style: TextStyle(
                            fontSize: 15,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        const SizedBox(height: 12),
                        _buildFilterSwitch(
                          '有电梯',
                          _hasElevator,
                          (value) {
                            setState(() {
                              _hasElevator = value;
                            });
                          },
                        ),
                        _buildFilterSwitch(
                          '需要包装',
                          _needPackaging,
                          (value) {
                            setState(() {
                              _needPackaging = value;
                            });
                          },
                        ),
                        _buildFilterSwitch(
                          '需要拆装',
                          _needDisassembly,
                          (value) {
                            setState(() {
                              _needDisassembly = value;
                            });
                          },
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }

  /// 构建筛选开关项
  Widget _buildFilterSwitch(
    String title,
    bool value,
    ValueChanged<bool> onChanged,
  ) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 8),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            title,
            style: TextStyle(
              fontSize: 14,
              color: Colors.grey[700],
            ),
          ),
          Switch(
            value: value,
            onChanged: onChanged,
            activeColor: const Color(0xFFFF5722),
          ),
        ],
      ),
    );
  }

  /// 显示抢单确认对话框
  Future<bool?> _showGrabOrderDialog(Order order) {
    return showDialog<bool>(
      context: context,
      builder: (context) => GrabOrderDialog(
        price: order.price,
        address: order.address,
        distance: order.distance,
        onConfirm: () {
          // 不需要在这里处理导航，由 dialog 返回值处理
        },
        onCancel: () {
          // 不需要在这里处理导航，由 dialog 返回值处理
        },
      ),
    );
  }

  /// 构建订单卡片
  Widget _buildOrderCard(Order order) {
    return GestureDetector(
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => OrderDetailPage(order: order),
          ),
        );
      },
      child: Container(
        margin: const EdgeInsets.fromLTRB(12, 0, 12, 12),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8),
          border: Border.all(
            color: const Color(0xFFEEEEEE),
          ),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.03),
              blurRadius: 8,
              offset: const Offset(0, 2),
            ),
          ],
        ),
        child: Material(
          color: Colors.transparent,
          child: InkWell(
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => OrderDetailPage(order: order),
                ),
              );
            },
            borderRadius: BorderRadius.circular(8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 订单头部
                Container(
                  padding: const EdgeInsets.all(12),
                  decoration: const BoxDecoration(
                    color: Color(0xFFFFF3E0),
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(8),
                      topRight: Radius.circular(8),
                    ),
                  ),
                  child: Row(
                    children: [
                      const Icon(
                        Icons.local_shipping_outlined,
                        size: 16,
                        color: Color(0xFFFF5722),
                      ),
                      const SizedBox(width: 4),
                      Text(
                        order.serviceType,
                        style: const TextStyle(
                          fontSize: 13,
                          color: Color(0xFFFF5722),
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                      const Spacer(),
                      // 时间信息
                      Container(
                        padding: const EdgeInsets.symmetric(
                          horizontal: 8,
                          vertical: 4,
                        ),
                        decoration: BoxDecoration(
                          color: Colors.white.withOpacity(0.8),
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Icon(
                              Icons.access_time,
                              size: 14,
                              color: Colors.grey[600],
                            ),
                            const SizedBox(width: 4),
                            Text(
                              order.time,
                              style: TextStyle(
                                fontSize: 13,
                                color: Colors.grey[600],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                // 地址信息
                Padding(
                  padding: const EdgeInsets.all(12),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Container(
                            width: 18,
                            height: 18,
                            decoration: BoxDecoration(
                              color: Colors.green[50],
                              shape: BoxShape.circle,
                            ),
                            child: Icon(
                              Icons.trip_origin,
                              size: 12,
                              color: Colors.green[400],
                            ),
                          ),
                          const SizedBox(width: 8),
                          Expanded(
                            child: Text(
                              order.fromAddress,
                              style: const TextStyle(
                                fontSize: 15,
                                height: 1.4,
                              ),
                            ),
                          ),
                          Container(
                            padding: const EdgeInsets.symmetric(
                              horizontal: 6,
                              vertical: 2,
                            ),
                            decoration: BoxDecoration(
                              color: Colors.blue[50],
                              borderRadius: BorderRadius.circular(4),
                            ),
                            child: Row(
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Icon(
                                  Icons.directions_car,
                                  size: 12,
                                  color: Colors.blue[700],
                                ),
                                const SizedBox(width: 2),
                                Text(
                                  '${order.distance.toStringAsFixed(1)}km',
                                  style: TextStyle(
                                    fontSize: 12,
                                    color: Colors.blue[700],
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                      Container(
                        width: 1,
                        height: 16,
                        margin: const EdgeInsets.only(left: 8),
                        color: Colors.grey[300],
                      ),
                      Row(
                        children: [
                          Container(
                            width: 18,
                            height: 18,
                            decoration: BoxDecoration(
                              color: Colors.red[50],
                              shape: BoxShape.circle,
                            ),
                            child: Icon(
                              Icons.location_on,
                              size: 12,
                              color: Colors.red[400],
                            ),
                          ),
                          const SizedBox(width: 8),
                          Expanded(
                            child: Text(
                              order.address,
                              style: const TextStyle(
                                fontSize: 15,
                                height: 1.4,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                // 订单要求
                if (order.requirements.isNotEmpty)
                  Padding(
                    padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
                    child: Wrap(
                      spacing: 8,
                      runSpacing: 8,
                      children: order.requirements.map((requirement) {
                        return Container(
                          padding: const EdgeInsets.symmetric(
                            horizontal: 8,
                            vertical: 4,
                          ),
                          decoration: BoxDecoration(
                            color: Colors.grey[100],
                            borderRadius: BorderRadius.circular(4),
                          ),
                          child: Text(
                            requirement,
                            style: TextStyle(
                              fontSize: 12,
                              color: Colors.grey[600],
                            ),
                          ),
                        );
                      }).toList(),
                    ),
                  ),
                // 分割线
                const Divider(height: 1,color: Color(0xFFF0F0F0)),
                // 底部操作栏
                Container(
                  padding: const EdgeInsets.all(12),
                  decoration: const BoxDecoration(
                    border: Border(
                      top: BorderSide(
                        color: Color(0xFFEEEEEE),
                        width: 1,
                      ),
                    ),
                  ),
                  child: Row(
                    children: [
                      // 价格显示
                      Text(
                        '¥${order.price.toStringAsFixed(2)}',
                        style: const TextStyle(
                          fontSize: 20,
                          color: Color(0xFFFF5722),
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      const Spacer(),
                      // 抢单按钮
                      Container(
                        height: 36,
                        decoration: BoxDecoration(
                          gradient: const LinearGradient(
                            colors: [
                              Color(0xFFFF7043),
                              Color(0xFFFF5722),
                            ],
                          ),
                          borderRadius: BorderRadius.circular(6),
                          boxShadow: [
                            BoxShadow(
                              color: const Color(0xFFFF5722).withOpacity(0.3),
                              blurRadius: 8,
                              offset: const Offset(0, 2),
                            ),
                          ],
                        ),
                        child: ElevatedButton(
                          onPressed: () => _handleGrabOrder(order),
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.transparent,
                            foregroundColor: Colors.white,
                            elevation: 0,
                            padding: const EdgeInsets.symmetric(
                              horizontal: 20,
                              vertical: 0,
                            ),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(6),
                            ),
                          ),
                          child: Row(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Icon(
                                Icons.flash_on,
                                size: 16,
                                color: Colors.white.withOpacity(0.9),
                              ),
                              const SizedBox(width: 4),
                              const Text(
                                '立即抢单',
                                style: TextStyle(
                                  fontSize: 14,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  /// 更新抢单处理方法
  Future<void> _handleGrabOrder(Order order) async {
    // 显示确认对话框
    final bool? confirm = await _showGrabOrderDialog(order);

    if (confirm == true) {
      try {
        // 模拟抢单成功
        if (mounted) {
          setState(() {
            _orders.removeWhere((o) => o.id == order.id);
          });
          
          // 显示成功提示并跳转
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Row(
                children: [
                  Container(
                    padding: const EdgeInsets.all(2),
                    decoration: BoxDecoration(
                      color: Colors.white.withOpacity(0.2),
                      shape: BoxShape.circle,
                    ),
                    child: const Icon(
                      Icons.check,
                      color: Colors.white,
                      size: 18,
                    ),
                  ),
                  const SizedBox(width: 8),
                  const Text('抢单成功'),
                ],
              ),
              backgroundColor: const Color(0xFF4CAF50),
              duration: const Duration(seconds: 2),
              behavior: SnackBarBehavior.floating,
              margin: const EdgeInsets.all(12),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8),
              ),
            ),
          );

          // 延迟跳转到订单详情
          Future.delayed(const Duration(milliseconds: 500), () {
            if (mounted) {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => OrderDetailPage(order: order),
                ),
              );
            }
          });
        }
      } catch (e) {
        // 显示错误提示
        if (mounted) {
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Row(
                children: [
                  Container(
                    padding: const EdgeInsets.all(2),
                    decoration: BoxDecoration(
                      color: Colors.white.withOpacity(0.2),
                      shape: BoxShape.circle,
                    ),
                    child: const Icon(
                      Icons.close,
                      color: Colors.white,
                      size: 18,
                    ),
                  ),
                  const SizedBox(width: 8),
                  const Text('抢单失败，请重试'),
                ],
              ),
              backgroundColor: Colors.red[700],
              duration: const Duration(seconds: 2),
              behavior: SnackBarBehavior.floating,
              margin: const EdgeInsets.all(12),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8),
              ),
            ),
          );
        }
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    // 使用筛选后的订单列表
    final filteredOrders = _filteredOrders;
    
    return Scaffold(
      backgroundColor: const Color(0xFFF5F5F5),
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.white,
        title: const Text(
          '抢单',
          style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        actions: [
          TextButton.icon(
            onPressed: _showFilterSheet,
            icon: const Icon(
              Icons.filter_list,
              size: 20,
            ),
            label: const Text('筛选'),
            style: TextButton.styleFrom(
              foregroundColor: Colors.grey[700],
            ),
          ),
        ],
      ),
      body: filteredOrders.isEmpty
          ? EmptyState(
              message: '暂无符合条件的订单',
              subMessage: '试试调整筛选条件',
              icon: Icons.local_shipping_outlined,
              onRefresh: _onRefresh,
            )
          : SmartRefresher(
              controller: _refreshController,
              enablePullDown: true,
              enablePullUp: true,
              header: CustomHeader(
                builder: (BuildContext context, RefreshStatus? mode) {
                  Widget body;
                  if (mode == RefreshStatus.idle) {
                    body = const Text("下拉刷新");
                  } else if (mode == RefreshStatus.refreshing) {
                    body = Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SizedBox(
                          width: 16,
                          height: 16,
                          child: CircularProgressIndicator(
                            strokeWidth: 2,
                            valueColor: AlwaysStoppedAnimation<Color>(
                              Color(0xFFFF5722),
                            ),
                          ),
                        ),
                        const SizedBox(width: 8),
                        const Text("加载中..."),
                      ],
                    );
                  } else if (mode == RefreshStatus.canRefresh) {
                    body = const Text("松开刷新");
                  } else if (mode == RefreshStatus.completed) {
                    body = const Text("刷新成功");
                  } else {
                    body = const Text("刷新失败");
                  }
                  return Container(
                    height: 44,
                    alignment: Alignment.center,
                    child: DefaultTextStyle(
                      style: TextStyle(
                        color: Colors.grey[600],
                        fontSize: 13,
                      ),
                      child: body,
                    ),
                  );
                },
              ),
              footer: CustomFooter(
                builder: (BuildContext context, LoadStatus? mode) {
                  Widget body;
                  if (mode == LoadStatus.idle) {
                    body = const Text("上拉加载更多");
                  } else if (mode == LoadStatus.loading) {
                    body = Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        SizedBox(
                          width: 16,
                          height: 16,
                          child: CircularProgressIndicator(
                            strokeWidth: 2,
                            valueColor: AlwaysStoppedAnimation<Color>(
                              Color(0xFFFF5722),
                            ),
                          ),
                        ),
                        const SizedBox(width: 8),
                        const Text("加载中..."),
                      ],
                    );
                  } else if (mode == LoadStatus.failed) {
                    body = const Text("加载失败，点击重试");
                  } else if (mode == LoadStatus.canLoading) {
                    body = const Text("松开加载更多");
                  } else {
                    body = const Text("没有更多数据了");
                  }
                  return SizedBox(
                    height: 44,
                    child: Center(
                      child: DefaultTextStyle(
                        style: TextStyle(
                          fontSize: 13,
                          color: Colors.grey[600],
                        ),
                        child: body,
                      ),
                    ),
                  );
                },
              ),
              onRefresh: _onRefresh,
              onLoading: _onLoading,
              child: ListView.builder(
                padding: const EdgeInsets.only(top: 12),
                itemCount: filteredOrders.length,
                itemBuilder: (context, index) => _buildOrderCard(filteredOrders[index]),
              ),
            ),
    );
  }
} 